<?php
if(!isset($_SESSION))
{
    session_start();
}

if( !function_exists('__autoload') )
{
    function __autoload($class_name) {
    require_once $class_name . '.php';
    }
}
$processo = stripslashes($_POST['itens']); // array serializado com os materiais do detalhamento


$str1 = preg_replace("/([a-zA-Z0-9_]+?):/" , "\"$1\":", $processo); // fix variable names 
$str2 = utf8_encode($str1);
if( !strstr($_POST['itens'], 'material' ) )
{
	$j = json_decode($str2);
}
else
{
	$str3 = str_replace('"{', '{', $str2  );
	$str4 = str_replace('}"', '}', $str3  );
	$j = json_decode($str4);
}


$itens = array();



for($i = 0; $i < count($j); $i++ )
{
	$itens[] = get_object_vars($j[$i]);
	if( !strstr($_POST['itens'], 'servico' ) )
	{
		$medida = get_object_vars($itens[$i]['medida']);
		$itens[$i] = array_merge( $itens[$i], $medida );
	}
}


if( !strstr($_POST['itens'], 'servico' ) )
	$itens = Material::ArrayParaObjetos( $itens );
else
	$itens = Servico::ArrayParaObjetos( $itens );
	
	

$t = json_encode($_POST);

function unescape($source, $iconv_to = 'UTF-8') {
    $decodedStr = '';
    $pos = 0;
    $len = strlen ($source);
    while ($pos < $len) {
        $charAt = substr ($source, $pos, 1);
        if ($charAt == '%') {
            $pos++;
            $charAt = substr ($source, $pos, 1);
            if ($charAt == 'u') {
                // we got a unicode character
                $pos++;
                $unicodeHexVal = substr ($source, $pos, 4);
                $unicode = hexdec ($unicodeHexVal);
                $decodedStr .= code2utf($unicode);
                $pos += 4;
            }
            else {
                // we have an escaped ascii character
                $hexVal = substr ($source, $pos, 2);
                $decodedStr .= chr (hexdec ($hexVal));
                $pos += 2;
            }
        }
        else {
            $decodedStr .= $charAt;
            $pos++;
        }
    }

    if ($iconv_to != "UTF-8") {
        $decodedStr = iconv("UTF-8", $iconv_to, $decodedStr);
    }
   
    return $decodedStr;
}


?>
<html>
           <head>
           <title>SAEO - Confirmar Cadastro do Processo</title>
           <link rel='stylesheet' type='text/css' href='templates/estilos.css'>
           <script type='text/javascript' src='templates/novo_detalhamento.js'></script>
           <script>
           </script>
           </head>
     <body class='body' onLoad=''>
     <form name='confirmar_cadastro_processo' action='EnviarDadosProcesso.php?operacao=1' method='post'>
     <input type='hidden' name='processo' value='<?php echo $t; ?>'>
     <table width='779' border='0' cellspacing='0' cellpadding='0' align='center' bgcolor='#FFFFFF'>
            <tr>
				<td><?php include "Topo.php"; ?> </td>
			</tr>
            <tr>
                <td><div class='titulosTabelas' style='width:779; height:20; background:url(templates/tabela.JPG)'>CONFIRMAR CADASTRO DO PROCESSO</div></td>
            </tr>
            <tr>
                <td colspan='2'>&nbsp;</td>
            </tr>
            <tr>
                <td><table class='tabela' width='655' border='0' cellspacing='0' cellpadding='0' align='center' bgcolor='#FFFFFF'>
                           <tr>
                               <td>&nbsp;</td>
                           </tr>
                           <tr>
                               <td class='textoTopicoConfirmacao'>I. Objeto:</td>
                           </tr>
                           <tr>
                               <td class='textoTabelas'><?php echo $_POST["objeto"] ?></td>
                           </tr>
                           <tr>
                               <td colspan='2'>&nbsp;</td>
                           </tr>
            <!--           <tr>
                               <td class='textoTopicoConfirmacao'>II. Justificativa:</td>
                           </tr>
                           <tr>
                               <td class='textoTabelas'><?php //echo $_POST["justificativa"] ?></td>
                           </tr>
                           <tr>
                               <td colspan='2'>&nbsp;</td>
                           </tr>-->
                           <tr>
                               <td class='textoTopicoConfirmacao'>III. Metas Fisicas:</td>
                           </tr>
                           <tr>
                               <td colspan='2'>&nbsp;</td>
                           </tr>
                           <tr>
                               <td class='subTextoConfirmacao'>3.1) Detalhamento:</td>
                           </tr>
                           <tr>
                               <td colspan='2'>&nbsp;</td>
                           </tr>
                           <tr>
                               <td>
                                   <table id='tabelaDetalhamento' border='0' width='100%' bgcolor='#e7efd1' class='detalhamento'>
                                          <thead class='detalhamento'>
                                          <tr>
                                              <th class='textoTabelaDetalhamento' width='3%'>N�</th>
                                              <th class='textoTabelaDetalhamento' width='62'>Especifica��o</th>
                                              <th class='textoTabelaDetalhamento' width='10%' >QTDE</th>
                                              <th class='textoTabelaDetalhamento' width='15%'>Vl. Unit�rio</th>
                                              <th class='textoTabelaDetalhamento' width='15%' >Valor Total</th>
                                          </tr>
                                          </thead>
                                          <tbody class='detalhamento'>
                                              <?php 
                                              for($i = 0; $i < count($itens); $i++ )
                                                {
                                              ?>
                                                   <tr style='text-align:center;<?php if( $i%2 != 0) echo "background-color:#FFFFFF"; ?>'>
                                                   		<td><?php echo $i+1 ?></td>
                                                   		<td style='text-align:justify;'><?php echo unescape($itens[$i]->especificacao); ?></td>
                                                   		<?php 
                                                   if( is_a($itens[$i], 'Material' ) )
                                                   {
                                                   ?>
                                                   		<td>&nbsp;<?php echo $itens[$i]->quantidade; ?></td>
                                                   		<td>R$&nbsp;<?php echo number_format($itens[$i]->valor/100,2,",","."); ?></td>	
                                                   		<td>R$&nbsp;<?php echo number_format(($itens[$i]->valor/100)*$itens[$i]->quantidade,2,",","."); ?></td>
                                                   <?php 
                                                   }
                                                   else
                                                   {
                                                   ?>	
                                                   		<td>N\A</td>
                                                   		<td>N\A</td>
                                                   		<td>N\A</td>
                                                   <?php 
                                                   }
                                                }
                                                   ?>	
                                                  </tr>
                                   </tbody>
                                   <tfoot class='detalhamento'>
                                   		<tr>
                                   			<td colspan='5'>&nbsp;</td>
                                   		</tr>
                                   </tfoot>
                                   </table>
                               </td>
                           </tr>
                           <tr>
                               <td >&nbsp;</td>
                           </tr>
                          <!--  <tr>
                               <td class='subTextoConfirmacao'>4.2) Das garantias:</td>
                           </tr>
                           <tr>
                               <td class='textoTabelas'><?php //echo $_POST["garantias"] ?></td>
                           </tr>
                           <tr>
                               <td colspan='2'>&nbsp;</td>
                           </tr>
                           <tr>
                               <td class='subTextoConfirmacao'>4.3) Assist�ncia t�cnica:</td>
                           </tr>
                           <tr>
                               <td class='textoTabelas'><?php //echo $_POST["assistenciaTecnica"] ?></td>
                           </tr>
                           <tr>
                               <td colspan='2'>&nbsp;</td>
                           </tr>
                           <tr>
                               <td class='subTextoConfirmacao'>4.4) Recebimento de Bens e/ou Servi�os (Local, Prazo, Condi��es):</td>
                           </tr>
                           <tr>
                               <td class='textoTabelas'><?php //echo $_POST["infoRecebimento"] ?></td>
                           </tr>
                           <tr>
                               <td colspan='2'>&nbsp;</td>
                           </tr>-->
                           <tr>
                               <td class='subTextoConfirmacao'>3.5) Valor referencia:</td>
                           </tr>
                           <tr>
                               <td class='subTextoTabelas'>R$ <?php echo number_format($_POST['valorReferencia']/100,2,",",".") ?></td>
                           </tr>
                           <tr>
                               <td colspan='2'>&nbsp;</td>
                           </tr>
                           <tr>
                               <td class='textoTopicoConfirmacao'>IV. Estratégia de Fornecimento e Recebimento do Material:</td>
                           </tr>
                           <tr>
                               <td class='textoTabelas'><?php echo $_POST["infoRecebimento"] ?></td>
                           </tr>
                           <tr>
                               <td colspan='2'>&nbsp;</td>
                           </tr>                           
                           <tr>
                               <td class='textoTopicoConfirmacao'>V. Obrigaçoes:</td>
                           </tr>
                           <tr>
                               <td colspan='2'>&nbsp;</td>
                           </tr>
                           <tr>
                               <td class='subTextoConfirmacao'>5.1) Do IFAL:</td>
                           </tr>
                           <tr>
                               <td class='textoTabelas'><?php echo $_POST["responsabilidadeIFAL"] ?></td>
                           </tr>
                           <tr>
                               <td colspan='2'>&nbsp;</td>
                           </tr>
                           <tr>
                               <td class='subTextoConfirmacao'>5.2) Do contratado:</td>
                           </tr>
                           <tr>
                               <td class='textoTabelas'><?php echo $_POST["responsabilidadeContratado"] ?></td>
                           </tr>
                           <tr>
                               <td colspan='2'>&nbsp;</td>
                           </tr>
                           <tr>
                               <td class='textoTopicoConfirmacao'>VI. Sancoes:</td>
                           </tr>
                           <tr>
                               <td class='textoTabelas'><?php echo $_POST["sancoes"] ?></td>
                           </tr>
                           <tr>
                               <td colspan='2'>&nbsp;</td>
                           </tr>
                           <!--  <tr>
                               <td class='textoTopicoConfirmacao'>8) Do Pagamento:</td>
                           </tr>
                           <tr>
                               <td class='textoTabelas'><?php //echo $_POST["pagamento"] ?></td>
                           </tr>
                           <tr>
                               <td colspan='2'>&nbsp;</td>
                           </tr> -->
                           <?php 
                           // verifica se o campo outras informa��es foi preenchido, caso tenha sido preenchido exibe o resultado
                           if( $_POST["outrasInformacoes"] != "" )
                           {
                               ?>
                               <tr>
                                   <td class='textoTopicoConfirmacao'>VII. Outras informacoes:</td>
                               </tr>
                               <tr>
                                   <td class='textoTabelas'><?php echo $_POST["outrasInformacoes"]; ?></td>
                               </tr>
                           <?php 
                           }
                           ?>
                           <tr>
                                <td colspan='2' height='46'><div style='position:relative;left:220px'><img style='width:100px;height:30px;cursor:pointer;' src='templates/btvoltar.JPG' onclick='javascript: history.go(-1);'>&nbsp
                               <input type='image' style='width:100px;height:30px;' src='templates/btavancar.JPG'/></div></td>
                           <tr>
                     </table>
                </td>
            </tr>
            <tr>
                <td>&nbsp;</td>
            </tr>
            <tfoot>
           <tr>
                <td colspan='2'>&nbsp;</td>
            </tr>
                   <tr><?php include 'rodapeCreditos.php'; ?></tr>
            </tfoot>
     </table>
     </form>
     </body>
     </html>